package com.wryyyyy.service.impl;

import com.wryyyyy.dto.PageBean;
import com.wryyyyy.dto.Result;
import com.wryyyyy.entity.Hist;
import com.wryyyyy.mapper.HistMapper;
import com.wryyyyy.service.IHistService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wryyyyy.utils.ImageUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

import static com.wryyyyy.utils.SystemConstants.DISH_IMAGE_PATH;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wryyyyy
 * @since 2023-11-12
 */
@Service
public class HistServiceImpl extends ServiceImpl<HistMapper, Hist> implements IHistService {
    @Resource
    private HistMapper histMapper;

    @Override
    public Result queryAll(String userId, Integer current, Integer size) {
        Integer start = (current - 1) * size;
        List<Hist> hists = histMapper.selectAll(userId, start, size);
        for (Hist hist : hists) {
            hist.getDish().setUrls(ImageUtil.getUrls(hist.getDish().getImages(), DISH_IMAGE_PATH));
        }
        Integer count = histMapper.countAll(userId);
        return Result.ok(new PageBean<>(hists, count));
    }
}
